package com.hengpeng.itfin.tools;

import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * 任务类
 * @author weiyuan
 */
public class Task implements Runnable {
	
	private Date initDate;
	
	private String name;
	
	public Task (String name) {
		this.initDate = new Date();
		this.name = name;
	}

	@Override
	public void run() {
		System.out.println(Thread.currentThread().getName() + "：任务["+this.name+"]创建在：" + this.initDate);
		System.out.println(Thread.currentThread().getName() + "：任务["+this.name+"]开始在：" + new Date());
		
		try {
			long duration = (long)(Math.random()*10);
			System.out.println(Thread.currentThread().getName() + "：任务["+this.name+"]在以下时间内完成：" + duration);
			TimeUnit.SECONDS.sleep(duration);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println(Thread.currentThread().getName() + "：任务["+this.name+"]完成：" + new Date());
	}

}
